const express = require('express')
const fileHandle  = require('../../src/utils/fileHandle')
const Unique = require('../../src/utils/Unique')
const createTime = require('../../src/utils/creatTime')
const router = express.Router()
// 获取店铺信息
router.get('/getShopMsg',async (req,res,next)=>{
    let {id} = req.query
    let data =  await fileHandle.read('../files/shop')
    const result = data.find(item=>item.id === id)
    res.send({
        code:200,
        data:result || {},
        msg:'OK'
    })
})
// 获取用户信息
router.get('/getUserMsg',async (req,res,next)=>{
    let {id} = req.query
    let data =  await fileHandle.read('../files/users')
    const result = data.find(item=>item.id === id)
    res.send({
        code:200,
        data:result || {},
        msg:'OK'
    })
})
// 定制用餐人数
router.post('/addPeople',async (req,res,next)=>{
    let {shopId,tableNum,people,UserId} = req.body;
    const data = {
        id:Unique(),
        UserId,
        shopId,
        tableNum,
        people,
        createTime:createTime()
    }
   await fileHandle.add('../files/table',data)
 
    res.send({
        code:200,
        msg:'OK'
    })
})
module.exports = router